/*!
 * @file color.cpp
 * @brief Ciało color.hh
 */

#include "engine/basic/color.hh"
using namespace std;

/*--------------------------------------------------------------------------*/

color::color() :
	r(), g(), b(), a(255) {
}

/*--------------------------------------------------------------------------*/

color::color(float r, float g, float b) :
	r(r), g(g), b(b), a(1.0) {
}

/*--------------------------------------------------------------------------*/

color::color(float r, float g, float b, float a) :
	r(r), g(g), b(b), a(a) {
}

/*--------------------------------------------------------------------------*/

color color::operator +(color p) const {
	color tmp(this->r + p.r, this->g + p.g, this->b + p.b, this->a + p.a);
	tmp.normalize();

	return tmp;
}

/*--------------------------------------------------------------------------*/

color color::operator -(color p) const {
	color tmp(this->r - p.r, this->g - p.g, this->b - p.b, this->a - p.a);
	tmp.normalize();

	return tmp;
}

/*--------------------------------------------------------------------------*/

color color::operator *(float l) const {
	color tmp(this->r * l, this->g * l, this->b * l, this->a * l);
	tmp.normalize();

	return tmp;
}

/*--------------------------------------------------------------------------*/

void color::normalize() {
	if (this->r > 1)
		this->r = 1;
	if (this->g > 1)
		this->g = 1;
	if (this->b > 1)
		this->b = 1;
	if (this->a > 1)
		this->a = 1;

	if (this->r < 0)
		this->r = 0;
	if (this->g < 0)
		this->g = 0;
	if (this->b < 0)
		this->b = 0;
	if (this->a < 0)
		this->a = 0;
}

/*--------------------------------------------------------------------------*/
